package com.aaa.qy127.controller;

import com.aaa.qy127.entity.DingDan;
import com.aaa.qy127.entity.Ruku;
import com.aaa.qy127.service.DingDanService;
import com.aaa.qy127.service.impl.DingDanServiceImpl;
import com.aaa.qy127.util.CodeAndMsg;
import com.aaa.qy127.util.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.*;

@RestController
@RequestMapping("/dingdan")
public class DingDanController {

    @Resource(name = "dingDanServiceImpl")
    private DingDanService dingDanService;

    /**
     * 插入一条订单
     * @param bookid
     * @param count
     * @param outprice
     * @param request
     */
    @RequestMapping("/insertDingDan")
    public CodeAndMsg insertDingDan(String bookid, String count, String outprice, HttpServletRequest request){
        CodeAndMsg codeAndMsg = dingDanService.insertDingDan(bookid, count, outprice, request);
        return codeAndMsg;
    }

    /**
     * 查询所有订单信息和搜索
     * @param dingDan
     * @return
     */
    @RequestMapping("/list")
    public Result queryAlldd(DingDan dingDan){
        Result result = dingDanService.queryAlldd(dingDan);
        return result;
    }

    /**
     * 查询一条订单详情信息
     * @param dingDan
     * @return
     */
    @RequestMapping("/onedd")
    public Result queryonedd(DingDan dingDan){
        Result result = dingDanService.getonedd(dingDan);
        return result;
    }

    /**
     * 付款 添加 订单
     * @param gwcid
     * @param totalcount
     * @param totalprice
     */
    @RequestMapping("/payment")
    public List<Map<String, Object>> payment(String gwcid, String totalcount, String totalprice, HttpServletRequest request){
        List<Map<String, Object>> payment = dingDanService.payment(gwcid, totalcount, totalprice, request);
        return payment;
    }

    /**
     * 根据查询到的 ddid 查询 该订单的 订单详情
     * @param request
     * @return
     */
    @RequestMapping("/mydingdanxiangqing")
    public List<Map<String, Object>> mydingdanxiangqing(HttpServletRequest request){
        List<Map<String, Object>> mydingdanxiangqing = dingDanService.mydingdanxiangqing(request);
        //System.out.println(mydingdanxiangqing);
        return mydingdanxiangqing;
    }

    /**
     * 订单审核
     * @param ddid
     * @return
     */
    @RequestMapping("shenhe")
    public String shenhe(Integer ddid){
        System.out.println(ddid);
        String shenhe = dingDanService.shenhe(ddid);
        return shenhe;
    }

}
